<?php
class LogModel extends Model
{
    //自动验证
    protected $_validate = array(array("user", "require", "用户必须！"), 
    array('log', 'require', "日志记录必须！"), array('operate', 'require', "日志记录必须！"));
    //自动完成创建日期
    protected $_auto = array(array('create_time', 'time', 1, 'function'));
    /**
     * 拼接日志文本信息
     * @example 用户登陆 $type = 4 
     * $log['user'] = 1; //用户ID
     * $log['table'] = 'user'; //操作表名
     * $log['id'] = 2; //操作数据表ID
     * $log['log'] = '用户登陆！'; // 日志记录描述
     * @param Int $type 类型（1添加 2修改 3删除 4登陆）
     * @param String $table 表名称
     * @param Array $log 信息数组
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function logTemplate ($type, $table, $log = array())
    {
        $data = array();
        $user = getLoginUserInfo();
        $data['user'] = $user['id'];
        $data['operate'] = $type;
        $data['table'] = $table;
        if ($log) {
            foreach ($log as $k => $v) {
                $data[$k] = $v;
            }
        }
        if ($type == 1) {
            //添加操作
            $data['log'] = '用户 ' . $user['id'] . ':' . $user['name'] . ' 添加！';
        } else if ($type == 2) {
            //修改操作
            $data['log'] = '用户 ' . $user['id'] . ':' . $user['name'] . ' 修改！';
        } else if ($type == 3) {
            //删除操作
            $data['log'] = '用户 ' . $user['id'] . ':' . $user['name'] . ' 登陆！';
        } else if ($type == 4) {
            $data['log'] = '用户 ' . $user['id'] . ':' . $user['name'] . ' 登陆！';
        }
        return $data;
    }
}
?> 